import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


@allure.feature('TestCase_04: 查看预约电话号码与个人中心用户名显示一致	')
@allure.issue(
    'https://www.tapd.cn/54441127/sparrow/tcase/view/1154441127001066034?url_cache_key=5b07a59231afaf505fb7dc2f4205dfae')
class TestCaseService04:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()
        # 车服务
        self.service_index_page = CommonPage(self.driver).get_service_index_page()
        self.service_city_page = CommonPage(self.driver).get_service_city_page()
        self.service_customer_hotline_page = CommonPage(self.driver).get_service_customer_hotline_page()
        self.service_driving_score_page = CommonPage(self.driver).get_service_driving_score_page()
        self.service_health_house_keeper_page = CommonPage(self.driver).get_service_health_house_keeper_page()
        self.service_maintenance_plan_page = CommonPage(self.driver).get_service_maintenance_page()
        self.service_my_reservation_page = CommonPage(self.driver).get_service_my_reservation_page()
        self.service_new_operating_page = CommonPage(self.driver).get_service_new_operating_page()
        self.service_reservation_page = CommonPage(self.driver).get_service_reservation_page()
        self.service_store_select_page = CommonPage(self.driver).get_service_store_select_page()
        self.service_time_page = CommonPage(self.driver).get_service_time_page()

        # 个人中心
        self.personal_index_page = CommonPage(self.driver).get_personal_index_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('service')
        XiaoMaUtils.close_app('personal')
        # XiaoMaUtils.clear_data('personal')
        self.driver.quit()

    @allure.story('step1:点击应用页,进入车辆管家')
    @pytest.mark.run(order=41)
    def test_service_04_1_click_list(self):
        try:
            self.launcher_index_page.click_app_list()
            self.launcher_app_list_page.click_appname(TestCase.SERVICE)
            time.sleep(5)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 查看是否进入车服务,点击去维保按钮")
    @pytest.mark.run(order=42)
    def test_service_04_2_click_service(self):
        try:
            assert self.service_index_page.is_display_service_index()
            self.service_index_page.click_maintain()
            self.service_reservation_page.is_display_service_reservation()
            time.sleep(5)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step3: 获取用户名称和电话,然后返回首页进入个人中心查看用户名称和电话")
    @pytest.mark.run(order=43)
    def test_service_04_3_click_service(self):
        try:
            text1 = self.service_reservation_page.get_ele_text(self.service_reservation_page.get_user_name())
            text2 = self.service_reservation_page.get_ele_text(self.service_reservation_page.get_user_number())
            self.service_reservation_page.click_home()
            self.launcher_index_page.click_app_list()
            self.launcher_app_list_page.click_appname(TestCase.PERSONAL)
            text3 = self.personal_index_page.get_ele_text(self.personal_index_page.get_personal_name())
            text4 = self.personal_index_page.get_ele_text(self.personal_index_page.get_personal_phone())
            text5 = text2[7:]
            text6 = text4[7:]
            if text1 == text3 and text5 == text6:
                print("用户名称一致")
            else:
                print("获取信息错误")
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == 'main__':
    # pass
    pytest.main("-s testcase_service_04.py")
